package com.campus.controller;


import com.campus.pojo.dto.BusDTO;
import com.campus.pojo.dto.BusPageQueryDTO;
import com.campus.pojo.vo.BusVO;
import com.campus.result.PageResult;
import com.campus.result.Result;
import com.campus.service.BusService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/bus")
public class BusController {
    @Autowired
    private BusService busService;

    /**
     * 分页查询
     */
    @GetMapping("/pageQuery")
    public Result<PageResult<BusVO>> pageQuery(BusPageQueryDTO busPageQueryDTO) {
        log.info("分页查询：{}", busPageQueryDTO);
        PageResult<BusVO> pageResult = busService.pageQuery(busPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 新增班车
     */
    @PostMapping
    public Result save(@RequestBody BusDTO busDTO) {
        log.info("新增班车：{}", busDTO);
        busService.save(busDTO);
        return Result.success();
    }

    /**
     * 批量删除班车
     */
    @DeleteMapping
    public Result deleteByIds(@RequestParam List<Long> ids) {
        log.info("批量删除班车：{}", ids);
        busService.deleteByIds(ids);
        return Result.success();
    }

    /**
     * 查询回显
     */
    @GetMapping("/{id}")
    public Result<BusVO> getById(@PathVariable Long id) {
        log.info("查询回显 id: {}", id);
        BusVO busVO = busService.getById(id);
        return Result.success(busVO);
    }

    /**
     * 修改班车信息
     */
    @PutMapping
    public Result update(@RequestBody BusDTO busDTO) {
        log.info("修改班车信息：{}", busDTO);
        busService.update(busDTO);
        return Result.success();
    }

    /**
     * 更改状态
     */
    @PutMapping("/{id}/{status}")
    public Result updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        log.info("更改状态：{}", status);
        busService.updateStatus(id, status);
        return Result.success();
    }



}
